package features.advance.jdk.concurrent;

/**
 * @author LIN
 * @date 2021-09-09
 */
public class ThreadLocalTest {

    public static void main(String[] args) {
        ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
        Thread t1 = new Thread(() -> {
            threadLocal.set(1);
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + ":" + threadLocal.get());
        });
        t1.setName("Thread-1");
        t1.start();
        Thread t2 = new Thread(() -> {
            threadLocal.set(2);
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + ":" + threadLocal.get());
        });
        t2.setName("Thread-2");
        t2.start();
    }

}
